package com.zry.fertilizer.ui.activity

import com.zry.fertilizer.R
import com.zry.fertilizer.adapter.OutgoingListAdapter
import com.zry.fertilizer.animation.RecyclerViewUtilKt
import com.zry.fertilizer.been.OutgoingBean
import com.zry.fertilizer.databinding.ActivityOutgoingListBinding
import com.zry.fertilizer.retrofit.HttpServer
import com.zry.fertilizer.retrofit.ShowUserView
import com.zry.fertilizer.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_outgoing_list.*
import kotlinx.android.synthetic.main.common_title.*

class OutgoingListActivity : BaseActivity(), ShowUserView {

    private var outgoingListBinding: ActivityOutgoingListBinding? = null
    private var outID: String? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_outgoing_list
    }

    override fun initData() {
        titleCenterText.text = "出库清单"
        commonLeftLinearLayout.setOnClickListener { finish() }
        outID = intent.getStringExtra("outID")
        outgoingListBinding = viewDataBinding as ActivityOutgoingListBinding
        HttpServer(this).getOutStockDetailList(outID!!, 1, 999, this)

        initRecycler()
    }

    private fun initRecycler() {
        recyclerViewUtilKt = RecyclerViewUtilKt(this, outgoingListRecycler)
        recyclerViewUtilKt?.initRecyclerView()

    }

    private fun initAdapter(outgoingList: MutableList<OutgoingBean>) {
        val outgoingListAdapter = OutgoingListAdapter(R.layout.item_outgoing_list, outgoingList)
        recyclerViewUtilKt?.setAdapter(outgoingListAdapter)
    }


    override fun toMainActivity(what: Int, data: Any) {
        when (what) {
            36 -> {
                val outgoingList = data as MutableList<OutgoingBean>
                initAdapter(outgoingList)
            }
        }
    }
}
